<template>
  <a-config-provider
    :locale="locale"
    :get-popup-container="getPopupContainer"
  >
    <div id="app">
      <router-view v-if="isRouterAlive" />
      <!-- 审批详情 -->
      <ApprovalDetails
        :title="'审批意见'"
        :business-id="approvalDetailsDialog.businessId"
        :visible="approvalDetailsDialog.visible"
        @cancel="approvalDetailsDialog.visible = false"
        @confirm="approvalDetailsDialog.visible = false"
      />
    </div>
  </a-config-provider>
</template>

<script>
import { domTitle, setDocumentTitle } from '@/utils/domUtil'
import { i18nRender } from '@/locales'
import ApprovalDetails from '@/components/approvalDetails'
import DevicePixelRatio from './utils/devicePixelRatio'
export default {
  components: {
    ApprovalDetails,
  },
  data() {
    return {
      isRouterAlive: true,
      approvalDetailsDialog: {
        visible: false,
        businessId: '',
      },
    }
  },
  provide() {
    return {
      locale: i18nRender,
      contentWidth: '',
      breadcrumbRender: null,
      reload: this.reload
    }
  },
  computed: {
    locale() {
      // 只是为了切换语言时，更新标题
      const { title } = this.$route.meta
      title && setDocumentTitle(`${i18nRender(title)} - ${domTitle}`)
      return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale
    },
  },
  created(){
    // new DevicePixelRatio().init()
  },
  methods: {
    reload () {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    },
    getPopupContainer(el, dialogContent) {
      if (dialogContent) {
        return dialogContent.getDialogWrap()
      } else {
        // 仅调整select组件
        return (el && el.classList.contains('ant-select') && el.parentNode) || document.body
      }
    },
  },
  mounted() {
    const user = JSON.parse(sessionStorage.getItem('ycloud-user_info'))
    // 存储用户信息
    if (user && Object.keys(this.$store.state.user.userInfo)?.length === 0) {
      let level = { CO: 0, BC: 1, PD: 2 }[user.currentPost?.code] ?? ''
      if (level || level == 0) sessionStorage.setItem('currentLevel', level)
      this.$store.commit('SET_USER', user)
    }
    this.$bus.$on('showApprovalDetailsDialog', (v) => {
      this.approvalDetailsDialog.visible = true
      this.approvalDetailsDialog.businessId = v
    })

    let fgs = ''
    if (this.$userType() === 'CO') {
      fgs = this.$currentPost().orgName
    }
    if (this.$userType() === 'BC') {
      fgs = '西南公司,' + this.$currentPost().orgName
    }
    if (this.$userType() === 'PD') {
      fgs = '西南公司,' + this.$currentPost().orgName + ',' + this.$currentPost().name
    }

    this.$store.commit('SET_FGS',fgs)
  },
}
</script>
<style>
@import 'assets/public/common.css';

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.container {
  height: 100%;
  width: 100%;
}

.left-container {
  overflow: hidden;
  position: relative;
  height: 100%;
}

.right-container {
  border-right: 1px solid #cecece;
  float: right;
  height: 100%;
  width: 340px;
  box-shadow: 0 0 5px 2px #aaa;
  position: relative;
  z-index: 2;
}

.gantt-messages {
  list-style-type: none;
  height: 50%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-left: 5px;
}

.gantt-messages > .gantt-message {
  background-color: #f4f4f4;
  box-shadow: inset 5px 0 #d69000;
  font-family: Geneva, Arial, Helvetica, sans-serif;
  font-size: 14px;
  margin: 5px 0;
  padding: 8px 0 8px 10px;
}
</style>
